//
//  HMTabBarController.m
//  weibo
//
//  Created by apple on 2016/11/12.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "HMTabBarController.h"
#import "HMNaviViewController.h"
#import "HMTabBar.h"
#import "HMComposeView.h"
@interface HMTabBarController ()

@end

@implementation HMTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    HMTabBar *tabbar = [[HMTabBar alloc]init];
    [self setValue:tabbar forKey:@"tabBar"];
    tabbar.addBtnBlock = ^(){
        HMComposeView *compose = [[HMComposeView alloc]initWithFrame:self.view.bounds];
        [self.view addSubview:compose];
//        printf("haode");
    };
    [self addChildeViewController];
}

-(void)addChildeViewController{
    
    NSMutableArray *marr = [NSMutableArray array];
    [marr addObject:[self getViewcontrollerclsName:@"HMHomeTableViewController" title:@"主页" imgName:@"tabbar_home" integer:0]];
    [marr addObject:[self getViewcontrollerclsName:@"HMDiscoverTableViewController" title:@"发现" imgName:@"tabbar_discover" integer:1]];
    [marr addObject:[self getViewcontrollerclsName:@"HMMessageTableViewController" title:@"消息" imgName:@"tabbar_message_center" integer:2]];
    [marr addObject:[self getViewcontrollerclsName:@"HMProfileTableViewController" title:@"我" imgName:@"tabbar_profile" integer:3]];
    
    self.viewControllers = marr;
}


-(UIViewController *)getViewcontrollerclsName:(NSString *)clsName title:(NSString *)title imgName:(NSString *)imgName integer:(NSInteger)integer{
    Class cls = NSClassFromString(clsName);
    UIViewController *vc = [[cls alloc]init];
    vc.title = title;
    vc.tabBarItem.tag = integer;
//    [vc.tabBarItem setImage:[UIImage imageNamed:@""]]im
    vc.tabBarItem.image = [[UIImage imageNamed:imgName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    tabbar_home_selected
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imgName]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
//    vc.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -3);
//    vc.tabBarItem.badgeValue = @"10";
//    vc.tabBarItem.badgeColor = [UIColor redColor];
//    vc.tabBarItem.imageInsets = UIEdgeInsetsMake(5,0,0, 0);
    
    [vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor orangeColor]} forState:UIControlStateNormal];
//    vc.tabBarController.tabBar.att
//    vc.tabBarItem.
    
    HMNaviViewController *navi = [[HMNaviViewController alloc]initWithRootViewController:vc];
    return navi;
}

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
    NSInteger inetger = 0;
    for (UIView* subview in tabBar.subviews) {
        if ([subview isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
                if (item.tag == inetger) {
                subview.transform = CGAffineTransformMakeScale(0.5, 0.5);
                    [UIView animateWithDuration:0.25 delay:0 usingSpringWithDamping:0.2 initialSpringVelocity:7 options:0 animations:^{
                        subview.transform = CGAffineTransformIdentity;
                        } completion:nil];
//                    for (UIView *v in subview.subviews) {
//                        v.transform = CGAffineTransformMakeScale(0.5, 0.5);
//                        if ([v isKindOfClass:NSClassFromString(@"UIImageView")]) {
//                            [UIView animateWithDuration:0.25 animations:^{
//                                v.transform = CGAffineTransformIdentity;
//                            }];
//                        }
                    
//                    }
                    
                    
//                }

            }
            inetger ++;
        }
    }
    
}


@end
